package com.masblearn;

public class FourDirFireStrategy  implements FireStrategy {
    private static final FourDirFireStrategy FOUR_DIR_FIRE_STRATEGY = new FourDirFireStrategy();

    private FourDirFireStrategy(){

    }

    public static FourDirFireStrategy getInstance(){
        return FOUR_DIR_FIRE_STRATEGY;
    }


    @Override
    public void fire(Tank tank) {
        int bx, by;
        Dir[] dirs =  Dir.values();
        switch (tank.dir) {
            case UP:
                bx = tank.x + Tank.TANK_WIDTH / 2 - Bullet.WIDTH / 2;
                by = tank.y - Bullet.HEIGHT / 2;

                for(int i=0;i<dirs.length;i++){
                    GameModel.getInstance().add(new Bullet(bx, by, dirs[i], tank.group));
                }
//                tank.tf.bulletList.add(new Bullet(bx, by, tank.dir, tank.group, tank.tf));
                break;
            case DOWN:
                bx = tank.x + Tank.TANK_WIDTH / 2 - Bullet.WIDTH / 2;
                by = tank.y + Tank.TANK_HEIGHT - Bullet.HEIGHT / 2;
                for(int i=0;i<dirs.length;i++){
                    GameModel.getInstance().add(new Bullet(bx, by, dirs[i], tank.group));
                }                break;
            case LEFT:
                bx = tank.x - Bullet.WIDTH / 2;
                by = tank.y + Tank.TANK_HEIGHT / 2 - Bullet.HEIGHT / 2;
                for(int i=0;i<dirs.length;i++){
                    GameModel.getInstance().add(new Bullet(bx, by, dirs[i], tank.group));
                }                break;
            case RIGHT:
                bx = tank.x + Tank.TANK_WIDTH - Bullet.WIDTH / 2;
                by = tank.y + Tank.TANK_HEIGHT / 2 - Bullet.HEIGHT / 2;
                for(int i=0;i<dirs.length;i++){
                    GameModel.getInstance().add(new Bullet(bx, by, dirs[i], tank.group));
                }                break;
            default:
                break;
        }

    }
}
